Building Dictionaries¶

In [1]:
topics = {}
topics['Monday'] = 'Dictionaries'
topics['Wednesday'] = 'More with dictionaries'
print(topics)
{'Monday': 'Dictionaries', 'Wednesday': 'More with dictionaries'}
In [2]:
fruit_scores = {
    'apple': '⭐️⭐️⭐️⭐️',
    'pear': '⭐️⭐️⭐️⭐️⭐️',
    'banana': '⭐️⭐️⭐️',
    'kumquat': '⭐️?',
    'durian': '🤮'
}

while True:
    fruit = input('Fruit: ')
    if not fruit:  # equivalent to  if fruit == ''
        break
    score = fruit_scores.get(fruit, '????')
    print(f'{fruit}: {score}')
Fruit: apple
apple: ⭐️⭐️⭐️⭐️
Fruit: kumquat
kumquat: ⭐️?
Fruit: durian
durian: 🤮
Fruit: watermelon
watermelon: ????
Fruit: jackfruit
jackfruit: ????
Fruit: 

Key Ideas¶

  • Building dictionaries
    • zipping lists together
    • inverting 1-to-1 dictionaries
    • reading from CSV

👩🏼‍🎨 Room Assignments¶

You are helping to organize the next WICS Skillathon, where students can come hear various speakers in CS provide brief workshops on various tech skills.

You have a list of speakers and a list of available rooms. You want to pair up speakers with a room.

Write a function that takes a list of speakers and a list of rooms (both having the same length) and returns a dictionary of room assignments.

room_assignments.py¶

🧑🏽‍🎨 Itineraries¶

Participants in your Skillathon have a list of speakers they want to hear.

Write a function that takes a list of speaker/time tuples and the dictionary from the last step and returns a list of speaker/room/time tuples.

If the speaker isn't found, use 'Unassigned' as the room.

room_assignments.py¶

👨🏼‍🎨 Inverting a Dictionary¶

The speaker-to-room dictionary was helpful for making individual itineraries.

Now the building-scheduling crew wants a dictionary that maps rooms to speakers.

Because the room-assignments dictionary is 1-to-1 (the keys and the values are all unique), we can do this.

Write a function that takes the room assignments and returns a new dictionary mapping rooms to speakers.

room_assignments.py¶

👨🏻‍🎨 Read from CSV¶

The various speakers have different audio-visual setups for their presentations.

One of your team members made a CSV file that indicates each speaker and their AV requests.

Write a function that takes a file name and returns a dictionary mapping speaker to AV request.

av_requests.csv¶

room_assignments.py¶

👩🏻‍🎨 Room AV Setup¶

Now make a dictionary that maps a room to the equipment needed for that room.

  • What data would you use?
  • What function will you write to do this?

Key Ideas¶

  • Building dictionaries
    • zipping lists together
    • inverting 1-to-1 dictionaries
    • reading from CSV
    • daisy-chain